package com.shuqi.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.shuqi.common.MyTask;
import com.shuqi.common.Urls;
import com.shuqi.common.utils.HttpCommonParamsUtils;
import com.shuqi.model.net.HttpRequest;
import com.shuqi.model.net.UrlManager;
import com.shuqi.model.net.listener.HttpRequestListener;
import com.shuqi.model.parse.parser.AccountBindGetValidationParser;


public class AcountBindValidationModel extends ModelBase implements HttpRequestListener {

    private HttpRequest httpRequest;
    private Context context;
    private String mobileStr = "";
    private int type;

    public AcountBindValidationModel(Context context) {
        this.context = context;
    }

    @Override
    public void action(int actionCode, Object object) {
        fireEvent(actionCode, object);
    }

    @Override
    public List<BasicNameValuePair> setParams() {
        return null;
    }

    @Override
    public String getRequestUrl() {
        return Urls.getValidationCodeUrl();
    }

    @Override
    public void onDestroy() {
        if (httpRequest != null) {
            httpRequest.abort();
        }
    }

    @Override
    public void loadData(Object... objs) {
        mobileStr = (String) objs[0];
        type = (Integer) objs[1];
        List<BasicNameValuePair> params = HttpCommonParamsUtils.getAccountBasicParams();
        BasicNameValuePair typeBasicNameValuePair =
                new BasicNameValuePair("type", String.valueOf(type));
        BasicNameValuePair phoneBasicNameValuePair = new BasicNameValuePair("phone", mobileStr);
        BasicNameValuePair interfaceBasicNameValuePair =
                new BasicNameValuePair("interface", "send");
        params.add(typeBasicNameValuePair);
        params.add(phoneBasicNameValuePair);
        params.add(interfaceBasicNameValuePair);

        this.httpRequest =
                new HttpRequest(context, UrlManager.COLUMN_DOMAIN_ACCOUNT, getRequestUrl(), params, this);
        this.httpRequest.setDataParseAdapter(new AccountBindGetValidationParser());
        MyTask.runInBackground(httpRequest, true);
    }
}
